//
//  MOWaitDoDetail_DoingViewCell.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/6/23.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOWaitDoDetail_DoingViewCell.h"

@interface MOWaitDoDetail_DoingViewCell ()<UITextFieldDelegate>

@property(nonatomic,strong)UILabel *titleLabel;

@property(nonatomic,strong)UILabel *valueLabel;

@property(nonatomic,strong)UITextField *textField;

@end

@implementation MOWaitDoDetail_DoingViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    //NSString *ID = [NSString stringWithFormat:@"Cell%ld%ld",(long)[indexPath section],(long)[indexPath row]];
    NSString *ID = @"MOWaitDoDetail_DoingViewCell";
    MOWaitDoDetail_DoingViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil){
        cell = [[MOWaitDoDetail_DoingViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell creatView];
    }
    return cell;
}


-(void)creatView
{
    [self addSubview:self.titleLabel];
    [self addSubview:self.valueLabel];
    [self addSubview:self.textField];
}


-(void)textFieldDidEndEditing:(UITextField *)textField
{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"waitDoDetail_Doing_idea" object:nil userInfo:@{@"text":textField.text}];
}

-(void)setModel:(MOWaitDoDetail_DoingModel *)model
{
    self.titleLabel.text = model.nameStr;
    
    self.valueLabel.text = model.valueStr;
    
    if ([model.isCenter integerValue]==1) {
        self.titleLabel.width = SCREEN_WIDTH - 40;
        self.titleLabel.font = [UIFont boldSystemFontOfSize:17];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.height = 18;
    }else{
        CGFloat nameWidth = [NSString labelAutoCalculateRectWith:[NSString stringWithFormat:@"%@:",model.nameStr] WithFont:FONT_SIZE(15) MaxSize:CGSizeMake(MAXFLOAT, 16)].width;
        self.titleLabel.width = nameWidth + 6;
        self.titleLabel.font = FONT_SIZE(15);
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        self.titleLabel.height = 16;
    }
    
    CGFloat height = [NSString labelAutoCalculateRectWith:model.valueStr WithFont:FONT_SIZE(15) MaxSize:CGSizeMake(SCREEN_WIDTH - 40 - self.titleLabel.width - 5, CGFLOAT_MAX)].height;
    height = height<18?18:height;
    self.valueLabel.frame = CGRectMake(self.titleLabel.right + 5, kHConversions(18), SCREEN_WIDTH - 40 - self.titleLabel.width - 5, height);
    self.titleLabel.centerY = self.valueLabel.centerY;
    
    self.textField.frame = CGRectMake(self.titleLabel.right + 5, kHConversions(18), SCREEN_WIDTH - 40 - self.titleLabel.width - 5, 16);
    if ([model.hasTextField integerValue]==1) {
        self.textField.hidden = NO;
        self.valueLabel.hidden = YES;
    }else{
        self.textField.hidden = YES;
        self.valueLabel.hidden = NO;
    }
    
}

+ (CGFloat)heightForMOWaitDoDetail_DoingViewCellAndModel:(MOWaitDoDetail_DoingModel *)model
{
    CGFloat width;
    if ([model.isCenter integerValue]==1) {
        width  = SCREEN_WIDTH - 40;
    }else{
        width = [NSString labelAutoCalculateRectWith:[NSString stringWithFormat:@"%@:",model.nameStr] WithFont:FONT_SIZE(15) MaxSize:CGSizeMake(MAXFLOAT, 16)].width;
    }
    CGFloat height = [NSString labelAutoCalculateRectWith:model.valueStr WithFont:FONT_SIZE(15) MaxSize:CGSizeMake(SCREEN_WIDTH - 40 - width - 5, CGFLOAT_MAX)].height;
    if (height<18) {
        height = 18;
    }
    return height + kHConversions(18)*2;
}

#pragma mark -- 懒加载
-(UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, kHConversions(19), SCREEN_WIDTH, 16)];
        _titleLabel.font = FONT_SIZE(15);
        _titleLabel.textColor = KBlackColor_2A2A2A;
    }
    return _titleLabel;
}

-(UILabel *)valueLabel
{
    if (!_valueLabel) {
        _valueLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        _valueLabel.font = FONT_SIZE(15);
        _valueLabel.textColor = KBlackColor_2A2A2A;
        _valueLabel.numberOfLines = 0;
    }
    return _valueLabel;
}

-(UITextField *)textField
{
    if (!_textField) {
        _textField = [[UITextField alloc]initWithFrame:CGRectMake(120, kHConversions(19), SCREEN_WIDTH - 140, 16)];
        _textField.textColor = KBlackColor_2A2A2A;
        _textField.font = FONT_SIZE(15);
        _textField.placeholder = @"请输入注办意见";
        _textField.delegate = self;
    }
    return _textField;
}




@end
